package org.ztr.yanai.blog.utils;

import org.ztr.yanai.blog.constant.Constants;

import java.util.regex.Pattern;

/**
 * @Author: ZhaoTR
 * @Date: Created in 2025/11/22 14:30
 * @Description: 参数验证工具类
 * @Version: 1.0
 */
public class ValidationUtil {

    private ValidationUtil() {
        throw new IllegalStateException("Utility class");
    }

    /**
     * 验证邮箱格式
     */
    public static boolean isValidEmail(String email) {
        if (email == null || email.trim().isEmpty()) {
            return false;
        }
        return Pattern.matches(Constants.Regex.EMAIL, email);
    }

    /**
     * 验证手机号格式
     */
    public static boolean isValidPhone(String phone) {
        if (phone == null || phone.trim().isEmpty()) {
            return false;
        }
        return Pattern.matches(Constants.Regex.PHONE, phone);
    }

    /**
     * 验证用户名格式（3-20位字母数字下划线）
     */
    public static boolean isValidUsername(String username) {
        if (username == null || username.trim().isEmpty()) {
            return false;
        }
        return Pattern.matches(Constants.Regex.USERNAME, username);
    }

    /**
     * 验证密码格式（6-20位）
     */
    public static boolean isValidPassword(String password) {
        if (password == null || password.trim().isEmpty()) {
            return false;
        }
        return Pattern.matches(Constants.Regex.PASSWORD, password);
    }

    /**
     * 验证字符串是否为空
     */
    public static boolean isEmpty(String str) {
        return str == null || str.trim().isEmpty();
    }

    /**
     * 验证字符串是否非空
     */
    public static boolean isNotEmpty(String str) {
        return !isEmpty(str);
    }

    /**
     * 验证对象是否为空
     */
    public static boolean isNull(Object obj) {
        return obj == null;
    }

    /**
     * 验证对象是否非空
     */
    public static boolean isNotNull(Object obj) {
        return obj != null;
    }
}
